<style type="text/css">
</style>
<template>
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100">
        <Form-item label="接口相对地址" prop="url">
            <i-input v-model="formValidate.url" placeholder="请输入接口相对地址"></i-input>
        </Form-item>
        <Form-item label="描述（可选)" prop="description">
            <i-input v-model="formValidate.description" placeholder="请输入描述"></i-input>
        </Form-item>
        <Form-item label="划分到规则组后的组ID（可选）" prop="forgroupid">
            <i-select v-model="formValidate.forgroupid" placeholder="请选择分配的物资分类">
                <template v-for="(item,index) in fortypeArr">
                    <i-option :value="item.Id">{{item.Value}}</i-option>
                </template>
            </i-select>
        </Form-item>
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
            <i-button type="ghost" style="margin-left: 8px">取消</i-button>
        </Form-item>
    </i-form>
</template>
<script>
    import apiUtil from '../../assets/utils/api_util';
    import baseUtil from '../../assets/utils/base-util';

    export default {
        data() {
            return {
                formValidate: {
                    //添加字段
                    url: '',
                    description: '',
                    forgroupid: '',

                },
                ruleValidate: {},
                fortypeArr: [],
            }
        },

        mounted: function () {
            this.getForTypeData();
        },

        methods: {
            //添加
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.addData(model);
                })
            },
            getForTypeData: function () {
                let that = this;

                let params = '';
                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.RuleGroupList, params, function (res) {
                    that.$Loading.finish();

                    that.fortypeArr = res.Msg;
                });
            },
            addData: function (model) {
                let that = this;

                let params = that.$qs.stringify(model);
                this.$Loading.start();

                apiUtil.post(that, apiUtil.urls.AddRuleItem, params, function (res) {
                    that.$Loading.finish();

                    that.$Modal.confirm({
                        title: '操作成功',
                        content: '请选择下一步操作',
                        okText: '继续添加',
                        cancelText: '返回列表',
                        onOk: () => {
                            that.$router.go(0);
                        },
                        onCancel: () => {
                            baseUtil.pageJump(that, '', 'RuleItemList')
                        }
                    });
                });
            },

            uploadList() {
                let that = this;
                this.imageList = that.$refs.upload ? that.$refs.upload.fileList : [];
                console.log('this.imageList:', this.imageList);
                // return ;
            },

        }
    }
</script>
